/** $Id: WidthModelUnitTest.java 63 2010-02-14 13:52:34Z aaron.day $ */
package org.crazydays.gameplan.map.swing;


import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.junit.*;

import static org.junit.Assert.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.map.Geometry;
import org.crazydays.gameplan.map.GridType;

/**
 * WidthModelUnitTest
 */
public class WidthModelUnitTest
{
    /**
     * Test getNextValue().
     */
    @Test
    public void testGetNextValue()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // setup
        WidthModel model = new WidthModel(geometry);

        // test
        int result = (Integer) model.getNextValue();

        // verify
        assertEquals("result", 650, result);
    }

    /**
     * Test getPreviousValue().
     */
    @Test
    public void testGetPreviousValue()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // setup
        WidthModel model = new WidthModel(geometry);

        // test
        int result = (Integer) model.getPreviousValue();

        // verify
        assertEquals("result", 630, result);
    }

    /**
     * Test getValue().
     */
    @Test
    public void testGetValue()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // setup
        WidthModel model = new WidthModel(geometry);

        // test
        int result = (Integer) model.getValue();

        // verify
        assertEquals("result", 640, result);
    }

    /**
     * Test addChangeListener(ChangeListener).
     */
    @Test
    public void testAddChangeListener()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // mocks
        ChangeListener listener = createMock(ChangeListener.class);

        // setup
        WidthModel model = new WidthModel(geometry);

        // replay
        replay(listener);

        // test
        model.addChangeListener(listener);

        // verify
        verify(listener);

        assertEquals("size", 1, model.listeners.size());
    }

    /**
     * Test removeChangeListener(ChangeListener).
     */
    @Test
    public void testRemoveChangeListener()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // mocks
        ChangeListener listener = createMock(ChangeListener.class);

        // setup
        WidthModel model = new WidthModel(geometry);
        model.listeners.add(listener);

        // replay
        replay(listener);

        // test
        model.removeChangeListener(listener);

        // verify
        verify(listener);

        assertEquals("size", 0, model.listeners.size());
    }

    /**
     * Test setValue(Object).
     */
    @Test
    public void testSetValue()
    {
        // objects
        Geometry geometry = new Geometry(480, 640, GridType.SQUARE, 20);

        // mocks
        ChangeListener listener = createMock(ChangeListener.class);

        // setup
        WidthModel model = new WidthModel(geometry);
        model.listeners.add(listener);

        // expect
        listener.stateChanged(isA(ChangeEvent.class));

        // replay
        replay(listener);

        // test
        model.setValue(500);

        // verify
        verify(listener);

        assertEquals("height", 500, geometry.getWidth());
    }
}
